<%@ page import="java.io.File,
                 ro.gateway.aida.db.DBFilesPersMan,
                 ro.gateway.aida.db.DBPersistenceToken,
                 ro.gateway.aida.db.PersistenceManager"%>
<%
     File docs_dir = new File(application.getRealPath( "/documents"));
     boolean dididoid = false;
     if (docs_dir.exists() && docs_dir.isDirectory()) {
          File[] files = docs_dir.listFiles();
          DBFilesPersMan pman = DBFilesPersMan.getManager(
             ( DBPersistenceToken ) PersistenceManager.tokenLookup( application ));
          for ( int i = 0; i < files.length; i++ ) {
               if (files[i].isFile()) {
                    try {
                         pman.saveFile( "/documents/" + files[i].getName(), files[i]);
                         %>File /documents/<%=files[i].getName()%> saved in bd<br/><%
                         %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a target="x" href="<%=request.getContextPath()%>/dbfile/documents/<%=files[i].getName()%>">Click for test</a><br/><%
                         dididoid = true;
                         out.flush();
                         if (files[i].delete()) {
                              out.println("&nbsp;&nbsp;&nbsp;&nbsp;and deleted<br/>");
                         } else {
                              out.println("&nbsp;&nbsp;&nbsp;&nbsp;and will be deleted<br/>");
                              files[i].deleteOnExit();
                         }
                    } catch (Exception ex) {
                         out.println("File:" + "/documents/" + files[i].getName() + " already in bd.<br/>");
                         out.flush();
                    }
               }
          }
     }
     if (!dididoid) {
          out.println("No documents to save in db<p/>");
     }

     dididoid = false;
     File logo_dir = new File(application.getRealPath( "/logos/temp/"));
     if (logo_dir.exists() && logo_dir.isDirectory()) {
          File[] files = logo_dir.listFiles();
          DBFilesPersMan pman = DBFilesPersMan.getManager(
             ( DBPersistenceToken ) PersistenceManager.tokenLookup( application ));
          for ( int i = 0; i < files.length; i++ ) {
               if (files[i].isFile()) {
                    try {
                         %>File /documents/<%=files[i].getName()%> saved in bd<br/><%
                         %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a target="x" href="<%=request.getContextPath()%>/dbfile/logos/temp/<%=files[i].getName()%>">Click for test</a><br/><%
                         dididoid = true;
                         if (files[i].delete()) {
                              out.println("&nbsp;&nbsp;&nbsp;&nbsp;and deleted<br/>");
                         } else {
                              files[i].deleteOnExit();
                              out.println("&nbsp;&nbsp;&nbsp;&nbsp;and will be deleted<br/>");
                         }
                         out.flush();
                    } catch (Exception ex) {
                         out.println("File:" + "/documents/" + files[i].getName() + " already in bd.<br/>");
                         out.flush();
                    }
               }
          }
     }
     if (!dididoid) {
          out.println("No logos to save in db");
     }
%>